function [ largestVelConComp ] = replaceMissingComponents( largestVelConComp, filteredCurve, nConnComp, nCol, y, counter )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

    if nConnComp > 1
        largestVelConComp = bwareafilt(filteredCurve, nConnComp, 'largest');
    end
    
    for i = 1:nCol
    
        y(i, 1) = sum(largestVelConComp(:, i) == 1);
    
    end
    
    
    %Displays a warning if function is forced to exit the recursive loop
    if counter == 400
    
    warning('Artifact removal may have failed. View results to ensure acuracy')
    
    end
    
    
    if sum(y == 0) > (0.05 * nCol) && counter < 400 %function can only be called recursively 400 times at most
        
        counter = counter + 1; %Ensures that the function does not get caught in a loop infinitely
        
        nConnComp = nConnComp + 1;
        [ largestVelConComp ] = replaceMissingComponents( largestVelConComp, filteredCurve, nConnComp, nCol, y, counter );
    
    
    else
        
        return
    
    end


end

